package com.sskj.b70.p.activity;

import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.R;
import com.sskj.b70.common.App;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.FabiOrderBean;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.FabiSellDetailActivity;


public class FabiSellDetailPresenter extends BasePresenter<FabiSellDetailActivity> {

    public void getOrderInfo(String orderNum, String tradeType, boolean isLoad) {
        httpService.tradeListDetail(tradeType, orderNum)
                .execute(new JsonCallBack<HttpData<FabiOrderBean>>(this, isLoad) {
                    @Override
                    public void _onSuccess(Response<HttpData<FabiOrderBean>> response) {
                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            if (response.body().getData().getPay_list().size() > 0) {
                                mView.updateUI(response.body().getData().getPay_list().get(0));
                            } else {
                                ToastUtil.showShort(App.INSTANCE.getString(R.string.strFabiSellDetailPresenter0));
                            }
                        }
                    }
                });
    }


    /**
     * 标记已付款
     *
     * @param orderNum
     */
    public void markPay(String orderNum1, String orderNum, String tradeType) {
        httpService.endTrade(MyAppLication.getID(), orderNum)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            getOrderInfo(orderNum1, tradeType, true);
                        }
                    }
                });
    }

    /**
     * 取消订单
     *
     * @param orderNum
     */
    public void cancleOrder(String orderNum1, String orderNum, String traderType) {

        httpService.cancelFabiTradeOrder(orderNum)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            getOrderInfo(orderNum1, traderType, true);
                        }
                    }
                });
    }

    /**
     * 账单申诉
     *
     * @param orderNum
     */
    public void allegeOrder(String orderNum1, String orderNum, String refer, String tradeType, String ss_type, String ss_reason) {
        httpService.ssReason(MyAppLication.getID(), orderNum, ss_type, ss_reason)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            getOrderInfo(orderNum1, tradeType, true);
                        }
                    }
                });
    }

    /**
     * 确认放行
     *
     * @param orderNum
     * @param pwd
     */
    public void letGo(String orderNum1, String tradeType, String orderNum, String pwd) {
        httpService.confirmFx(MyAppLication.getID(), orderNum, pwd)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getStatus() == HttpConfig.STATUS_OK) {
                            getOrderInfo(orderNum1, tradeType, true);
                        }
                    }
                });
    }
}
